package Paineis;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;

import Botao.BotaoMateriais;
import Botao.BotaoSimples;
import Main.GamePanel;
import Utils.Utilidades;

public class PainelDeGerenciamento {
	public int x;
	public int y;
	public int width;
	public int height;
	final public BufferedImage fundo;
	public BufferedImage[] MateriaisBasicos;
	public boolean mouseOver;
	
	
	// botoes 
	public BotaoMateriais botaoTorre;
	public BotaoMateriais botaoMadeira;
	public BotaoMateriais botaoPedra;
	public BotaoMateriais botaoMetal;
	public BotaoSimples botaoConfirm;
	public BotaoSimples botaoCancel;
	public BotaoSimples botaoSell;
	public BotaoSimples botaoRepair;
	
	
	
	
	// definicao de constantes para os materiais 
	public final int  MADEIRA = 0;
	public final int  PEDRA = 1;
	public final int  METAL = 2;
	public boolean torreSelecionada;
//	public boolean prontoPraVenda = false;
//	Font arial = new Font("Arial", 14, Font.BOLD);
//	Font fontAnterior;
	

	public PainelDeGerenciamento(int X, int Y, int Width, int Height, String FileOpenImage) {
		//inicializacao 
		this.x = X;
		this.y = Y;
		this.width = Width;
		this.height = Height;
				
		fundo = Utilidades.LoadImage(FileOpenImage);
		torreSelecionada = false;
		inicializaBotoes();
	}
	
	public void inicializaBotoes(){
		// botoes de materiais para o craft		
		botaoTorre = new BotaoMateriais(736, 177, "/botoes/botao_torre.png","/botoes/botao_torre_over.png");
		botaoMadeira = new BotaoMateriais(736, 75, "/botoes/botao_madeira.png", "/botoes/botao_madeira_over.png");
		botaoPedra = new BotaoMateriais(736, 108, "/botoes/botao_pedra.png", "/botoes/botao_pedra_over.png");
		botaoMetal = new BotaoMateriais(736, 140, "/botoes/botao_metal.png", "/botoes/botao_metal_over.png");
		// botoes de confirmacao de compra, cancelamento, venda e conserto
		botaoConfirm = new BotaoSimples(736, 396, "/botoes/botao_confirma.png", "/botoes/botao_confirma_over.png");
		botaoCancel = new BotaoSimples(820, 396, "/botoes/botao_cancel.png", "/botoes/botao_cancel_over.png");
		botaoSell = new BotaoSimples(737, 435, "/botoes/botao_vender.png", "/botoes/botao_vender_over.png");
		botaoRepair = new BotaoSimples(735, 463, "/botoes/botao_conserto.png", "/botoes/botao_conserto_over.png");
	}
	
	public void Draw(Graphics2D dbg){
//		fontAnterior = dbg.getFont();
		if(fundo==null){
			dbg.setColor(Color.BLACK);
			dbg.fillRect(x, y, width, height);
		}else{
			dbg.drawImage(fundo, x, y, width, height, null);
		}
//		if(prontoPraVenda){
			botaoCancel.Draw(dbg);
			
//		}
		botaoMadeira.Draw(dbg);
		botaoPedra.Draw(dbg);
		botaoMetal.Draw(dbg);
		botaoTorre.Draw(dbg);
		if(torreSelecionada){
			botaoRepair.Draw(dbg);
			botaoSell.Draw(dbg);
		}else{
			botaoConfirm.Draw(dbg);
		}
//		dbg.setFont(arial);
		dbg.setColor(Color.YELLOW);
		dbg.drawString(""+GamePanel.money, 770, 40);
//		dbg.setFont(fontAnterior);
		
	}
	
	public void Update(long diffTime){
		
	}
	
	
	public void mouseMoved(MouseEvent e) {
		if(e.getY()>390){

			if(torreSelecionada){
				botaoRepair.mouseMoved(e);
				botaoSell.mouseMoved(e);
			}else{
				botaoConfirm.mouseMoved(e);
			}
			botaoCancel.mouseMoved(e);
				

			
			
		}else{
			botaoMadeira.mouseMoved(e);
			botaoPedra.mouseMoved(e);
			botaoMetal.mouseMoved(e);
			botaoTorre.mouseMoved(e);
		}
		
		
		
	}
	
	public void mouseDragged(MouseEvent e) {
		
	}
	
	public void mouseReleased(MouseEvent e) {
		
	}

	
	public void mousePressed(MouseEvent e) {
//		if(e.getY()>390){
//			if(prontoPraVenda){
//				botaoCancel.mouseClicked(e);
//				botaoConfirm.mouseClicked(e);
//			}			
//			botaoRepair.mouseClicked(e);
//			botaoSell.mouseClicked(e);
//		}else{
//			botaoMadeira.mouseClicked(e);
//			botaoPedra.mouseClicked(e);
//			botaoMetal.mouseClicked(e);
//			botaoTorre.mouseClicked(e);
//		}
	

	}

	
	public void mouseExited(MouseEvent e) {
	

	}


	public void mouseEntered(MouseEvent e) {
		

	}

	
	public void mouseClicked(MouseEvent e) {
		if(e.getY()>390){
//			if(prontoPraVenda){
				botaoCancel.mouseClicked(e);
				botaoConfirm.mouseClicked(e);
//			}			
			botaoRepair.mouseClicked(e);
			botaoSell.mouseClicked(e);
		}else{
			botaoMadeira.mouseClicked(e);
			botaoPedra.mouseClicked(e);
			botaoMetal.mouseClicked(e);
			botaoTorre.mouseClicked(e);
		}
		
		
		
	}
	
	
	
	
	

}
